home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #define MAX_FILENAME 34
- #define MAX_LINEWIDTH 512
-
- char transdate[10];
- char cknumber[8];
- char payToFrom[60];
- char account[60], deposit[20], withdrawal[20];
- char Cleared[5], flag[8], description[60];
-
- char account1[60], deposit1[20], withdrawal1[20];
- char Cleared1[5], flag1[8], description1[60];
- char account2[60], deposit2[20], withdrawal2[20];
- char Cleared2[5], flag2[8], description2[60];
- char account3[60], deposit3[20], withdrawal3[20];
- char Cleared3[5], flag3[8], description3[60];
- char account4[60], deposit4[20], withdrawal4[20];
- char Cleared4[5], flag4[8], description4[60];
- char account5[60], deposit5[20], withdrawal5[20];
- char Cleared5[5], flag5[8], description5[60];
- char account6[60], deposit6[20], withdrawal6[20];
- char Cleared6[5], flag6[8], description6[60];
- char account7[60], deposit7[20], withdrawal7[20];
- char Cleared7[5], flag7[8], description7[60];
- char account8[60], deposit8[20], withdrawal8[20];
- char Cleared8[5], flag8[8], description8[60];
- char account9[60], deposit9[20], withdrawal9[20];
- char Cleared9[5], flag9[8], description9[60];
- char account10[60], deposit10[20], withdrawal10[20];
- char Cleared10[5], flag10[8], description10[60];
- FILE *outfptr;
- main()
- {
- FILE *infptr;
- char infname[MAX_FILENAME], Htype[20];
- char outfname[MAX_FILENAME];
- char curr_line [MAX_LINEWIDTH];
- char procedure_line [MAX_LINEWIDTH];
- char teststr[MAX_LINEWIDTH];
-
-
- char c;
- int count,i;
-
- i=0;
- printf("File Name? ");
- gets(infname);
-
- printf("Enter HEADER TYPE (Bank, Cash, CCard, Oth A, Oth L, Invest...): ");
- gets(Htype);
- printf("\n\n\n");
-
- infptr = fopen(infname,"r");
-
- if (!infptr)
- {
- printf("\n\nError opening the file: %s\n",infname);
- printf("\n(Please hit the RETURN key to continue)");
-
- exit(0);
- }
- else
- {
- strcpy(outfname,infname);
- strcat(outfname,".QIF");
- outfptr = fopen(outfname,"w");
-
- fprintf(outfptr,"!Type:%s\n",Htype);
- while (!feof(infptr))
- {
- fgets(curr_line,MAX_LINEWIDTH,infptr);
- getfield(teststr,curr_line,1);
- if (isdate(teststr))
- {
- count = 0;
- i=i+1;
- dumpit();
- printf("Number of Transactions Converted: %i\r",i);
- account1[0]=account2[0]=account3[0]=account4[0]=account5[0]=account6[0]=account7[0]=account8[0]=account9[0]=account10[0]=0;
- deposit1[0]=deposit2[0]=deposit3[0]=deposit4[0]=deposit5[0]=deposit6[0]=deposit7[0]=deposit8[0]=deposit9[0]=deposit10[0]=0;
- withdrawal1[0]=withdrawal2[0]=withdrawal3[0]=withdrawal4[0]=withdrawal5[0]=withdrawal6[0]=withdrawal7[0]=withdrawal8[0]=withdrawal9[0]=withdrawal10[0]=0;
- Cleared1[0]=Cleared2[0]=Cleared3[0]=Cleared4[0]=Cleared5[0]=Cleared6[0]=Cleared7[0]=Cleared8[0]=Cleared9[0]=Cleared10[0]=0;
- flag1[0]=flag2[0]=flag3[0]=flag4[0]=flag5[0]=flag6[0]=flag7[0]=flag8[0]=flag9[0]=flag10[0]=0;
- description1[0]=description2[0]=description3[0]=description4[0]=description5[0]=description6[0]=description7[0]=description8[0]=description9[0]=description10[0]=0;
-
- strcpy(transdate,teststr);
- getfield(cknumber,curr_line,2);
- getfield(payToFrom,curr_line,3);
- getfield(account,curr_line,4);
- getfield(deposit,curr_line,5);
- getfield(withdrawal,curr_line,6);
- getfield(Cleared,curr_line,7);
- getfield(flag,curr_line,8);
- getfield(description,curr_line,11);
- }
- else
- {
- count= count + 1;
- if (count == 1)
- {
- getfield(account1,curr_line,4);
- getfield(deposit1,curr_line,5);
- getfield(withdrawal1,curr_line,6);
- getfield(Cleared1,curr_line,7);
- getfield(flag1,curr_line,8);
- getfield(description1,curr_line,11);
- }
- else if (count == 2)
- {
- getfield(account2,curr_line,4);
- getfield(deposit2,curr_line,5);
- getfield(withdrawal2,curr_line,6);
- getfield(Cleared2,curr_line,7);
- getfield(flag2,curr_line,8);
- getfield(description2,curr_line,11);
- }
- else if (count == 3)
- {
- getfield(account3,curr_line,4);
- getfield(deposit3,curr_line,5);
- getfield(withdrawal3,curr_line,6);
- getfield(Cleared3,curr_line,7);
- getfield(flag3,curr_line,8);
- getfield(description3,curr_line,11);
- }
- else if (count == 4)
- {
- getfield(account4,curr_line,4);
- getfield(deposit4,curr_line,5);
- getfield(withdrawal4,curr_line,6);
- getfield(Cleared4,curr_line,7);
- getfield(flag4,curr_line,8);
- getfield(description4,curr_line,11);
- }
- else if (count == 5)
- {
- getfield(account5,curr_line,4);
- getfield(deposit5,curr_line,5);
- getfield(withdrawal5,curr_line,6);
- getfield(Cleared5,curr_line,7);
- getfield(flag5,curr_line,8);
- getfield(description5,curr_line,11);
- }
- else if (count == 6)
- {
- getfield(account6,curr_line,4);
- getfield(deposit6,curr_line,5);
- getfield(withdrawal6,curr_line,6);
- getfield(Cleared6,curr_line,7);
- getfield(flag6,curr_line,8);
- getfield(description6,curr_line,11);
- }
- else if (count == 7)
- {
- getfield(account7,curr_line,4);
- getfield(deposit7,curr_line,5);
- getfield(withdrawal7,curr_line,6);
- getfield(Cleared7,curr_line,7);
- getfield(flag7,curr_line,8);
- getfield(description7,curr_line,11);
- }
- else if (count == 8)
- {
- getfield(account8,curr_line,4);
- getfield(deposit8,curr_line,5);
- getfield(withdrawal8,curr_line,6);
- getfield(Cleared8,curr_line,7);
- getfield(flag8,curr_line,8);
- getfield(description8,curr_line,11);
- }
- else if (count == 9)
- {
- getfield(account9,curr_line,4);
- getfield(deposit9,curr_line,5);
- getfield(withdrawal9,curr_line,6);
- getfield(Cleared9,curr_line,7);
- getfield(flag9,curr_line,8);
- getfield(description9,curr_line,11);
- }
- else if (count == 10)
- {
- getfield(account10,curr_line,4);
- getfield(deposit10,curr_line,5);
- getfield(withdrawal10,curr_line,6);
- getfield(Cleared10,curr_line,7);
- getfield(flag10,curr_line,8);
- getfield(description10,curr_line,11);
- }
- }
- }
- dumpit();
- }
- fclose(infptr);
- fclose(outfptr);
- printf("\n\nCONVERSION SUCCESSFULLY COMPLETED!!!\n\n(Please hit the RETURN key to continue)");
- }
-
- dumpit()
- {
-
- fprintf(outfptr,"D%s\n",transdate);
- if (deposit[0] != 0)
- fprintf(outfptr,"T%s\n",deposit);
- if (withdrawal[0] != 0)
- fprintf(outfptr,"T-%s\n",withdrawal);
- if (Cleared[0] != 0)
- fprintf(outfptr,"C*\n");
- if (cknumber[0] != 0)
- fprintf(outfptr,"N%s\n",cknumber);
- fprintf(outfptr,"P%s\n",payToFrom);
- if (description[0] != 0)
- fprintf(outfptr,"M%s\n",description);
- fprintf(outfptr,"L%s\n",account1);
- if (account2[0] !=0)
- {
- fprintf(outfptr,"S%s\n",account1);
- fprintf(outfptr,"E%s\n",description1);
- if (deposit1[0] != 0)
- fprintf(outfptr,"$-%s\n",deposit1);
- if (withdrawal1[0] != 0)
- fprintf(outfptr,"$%s\n",withdrawal1);
-
- fprintf(outfptr,"S%s\n",account2);
- fprintf(outfptr,"E%s\n",description2);
- if (deposit2[0] != 0)
- fprintf(outfptr,"$-%s\n",deposit2);
- if (withdrawal2[0] != 0)
- fprintf(outfptr,"$%s\n",withdrawal2);
-
- }
- if (account3[0] !=0)
- {
- fprintf(outfptr,"S%s\n",account3);
- fprintf(outfptr,"E%s\n",description3);
- if (deposit3[0] != 0)
- fprintf(outfptr,"$-%s\n",deposit3);
- if (withdrawal3[0] != 0)
- fprintf(outfptr,"$%s\n",withdrawal3);
- }
- if (account4[0] !=0)
- {
- fprintf(outfptr,"S%s\n",account4);
- fprintf(outfptr,"E%s\n",description4);
- if (deposit4[0] != 0)
- fprintf(outfptr,"$-%s\n",deposit4);
- if (withdrawal4[0] != 0)
- fprintf(outfptr,"$%s\n",withdrawal4);
- }
- if (account5[0] !=0)
- {
- fprintf(outfptr,"S%s\n",account5);
- fprintf(outfptr,"E%s\n",description5);
- if (deposit5[0] != 0)
- fprintf(outfptr,"$-%s\n",deposit5);
- if (withdrawal5[0] != 0)
- fprintf(outfptr,"$%s\n",withdrawal5);
- }
- if (account6[0] !=0)
- {
- fprintf(outfptr,"S%s\n",account6);
- fprintf(outfptr,"E%s\n",description6);
- if (deposit6[0] != 0)
- fprintf(outfptr,"$-%s\n",deposit6);
- if (withdrawal6[0] != 0)
- fprintf(outfptr,"$%s\n",withdrawal6);
- }
- if (account7[0] !=0)
- {
- fprintf(outfptr,"S%s\n",account7);
- fprintf(outfptr,"E%s\n",description7);
- if (deposit7[0] != 0)
- fprintf(outfptr,"$-%s\n",deposit7);
- if (withdrawal7[0] != 0)
- fprintf(outfptr,"$%s\n",withdrawal7);
- }
- if (account8[0] !=0)
- {
- fprintf(outfptr,"S%s\n",account8);
- fprintf(outfptr,"E%s\n",description8);
- if (deposit8[0] != 0)
- fprintf(outfptr,"$-%s\n",deposit8);
- if (withdrawal8[0] != 0)
- fprintf(outfptr,"$%s\n",withdrawal8);
- }
- if (account9[0] !=0)
- {
- fprintf(outfptr,"S%s\n",account9);
- fprintf(outfptr,"E%s\n",description9);
- if (deposit9[0] != 0)
- fprintf(outfptr,"$-%s\n",deposit9);
- if (withdrawal9[0] != 0)
- fprintf(outfptr,"$%s\n",withdrawal9);
- }
- if (account10[0] !=0)
- {
- fprintf(outfptr,"S%s\n",account10);
- fprintf(outfptr,"E%s\n",description10);
- if (deposit10[0] != 0)
- fprintf(outfptr,"$-%s\n",deposit10);
- if (withdrawal10[0] != 0)
- fprintf(outfptr,"$%s\n",withdrawal10);
- }
-
- fprintf(outfptr,"^\n");
-
-
-
-
-
- /* printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",transdate,cknumber,payToFrom,account,deposit,withdrawal,Cleared,flag,description);
- if (account1[0] != 0)
- printf("%s\t%s\t%s\t%s\t%s\t%s\n",account1,deposit1,withdrawal1,Cleared1,flag1,description1);
- if (account2[0] != 0)
- printf("%s\t%s\t%s\t%s\t%s\t%s\n",account2,deposit2,withdrawal2,Cleared2,flag2,description2);
- if (account3[0] != 0)
- printf("%s\t%s\t%s\t%s\t%s\t%s\n",account3,deposit3,withdrawal3,Cleared3,flag3,description3);
- if (account4[0] != 0)
- printf("%s\t%s\t%s\t%s\t%s\t%s\n",account4,deposit4,withdrawal4,Cleared4,flag4,description4);
- if (account5[0] != 0)
- printf("%s\t%s\t%s\t%s\t%s\t%s\n",account5,deposit5,withdrawal5,Cleared5,flag5,description5);
- if (account6[0] != 0)
- printf("%s\t%s\t%s\t%s\t%s\t%s\n",account6,deposit6,withdrawal6,Cleared6,flag6,description6);
- if (account7[0] != 0)
- printf("%s\t%s\t%s\t%s\t%s\t%s\n",account7,deposit7,withdrawal7,Cleared7,flag7,description7);
- if (account8[0] != 0)
- printf("%s\t%s\t%s\t%s\t%s\t%s\n",account8,deposit8,withdrawal8,Cleared8,flag8,description8);
- if (account9[0] != 0)
- printf("%s\t%s\t%s\t%s\t%s\t%s\n",account9,deposit9,withdrawal9,Cleared9,flag9,description9);
- if (account10[0] != 0)
- printf("%s\t%s\t%s\t%s\t%s\t%s\n",account10,deposit10,withdrawal10,Cleared10,flag10,description10);
- */
- }
-
- /* extracts the fieldno'th field string (s1) which is separated from other strings by */
- /* a TAB. This string is taken from a string (s2) */
- getfield(s1,s2,fieldno)
- char *s1,*s2;
- int fieldno;
- {
- int count;
-
- count = 0;
- fieldno = fieldno -1;
-
- if (fieldno == 0)
- {
- while (*s2 != 0 && *s2 != '\t')
- *s1++ = *s2++;
- *s1 = 0;
- }
- else
- {
- while (*s2 != 0 && count != fieldno)
- {
- if (*s2++ == '\t')
- count = count + 1;
- }
-
- while (*s2 != 0 && *s2 != '\t')
- *s1++ = *s2++;
- *s1 = 0;
- }
- }
-
- /* checks to see if str is a date. Really only checks to see if there are 2 '/' in the */
- /* str. very crude! */
- isdate(str)
- char *str;
- {
-
- int count;
-
- count = 0;
- while (*str)
- {
- if (*str++ == '/')
- count = count +1;
- }
- if (count == 0)
- return(0);
- return(1);
- }
-
-